﻿using Super_Management_Mayhem.Content.Spritesheet;
using Super_Management_Mayhem.Screens.Playing.ObjectInterfaces;
using Super_Management_Mayhem.Screens.Playing.Players;
using Transformable_Engine_v2.Engine.Animation.PositionAnimation;
using Transformable_Engine_v2.Engine.Animation.Trajectory;
using Transformable_Engine_v2.Engine.GameObjects.Containers;
using Transformable_Engine_v2.Engine.Transformable_Math.Geometry;

namespace Super_Management_Mayhem.Screens.Playing.Items
{
    public class ClassChanger : Container, ICollectible, IOrderable
    {
        static readonly TE_Rectangle HitBox = new TE_Rectangle(0, 0, 1, 1, TE_Rectangle.Alignment.CenterMiddle).ToGridBound();

        private ItemSheet.Classes _nextClass;
        public ClassChanger(ItemSheet.Classes nextClass)
        {
            _nextClass = nextClass;

            AddChildren(new ImageContainer {
                                               Sprite = ItemSheet.GetSprite(ItemSheet.Classes.Pedestral),
                                               Origin = TE_Rectangle.Alignment.CenterMiddle
                                           });

            var item = new ImageContainer {
                                              PositionGridBound = new TE_Vector2(0, -0.5f),
                                              Sprite = ItemSheet.GetSprite(nextClass),
                                              Origin = TE_Rectangle.Alignment.CenterMiddle
                                          };
            item.AddAnimations(new PositionAnimation(new SinusTrajectory(), new TE_Vector2(0, -0.75f), 1000, true, 0));
            AddChildren(item);
        }

        public TE_Rectangle GetBoundingBoxCollect()
        {
            return HitBox + AbsolutePosition;
        }

        public void Collect(PlayerContainer collector)
        {
            collector.ChangeClass(_nextClass);

            Die();
        }

        public float GetOrderingFactor()
        {
            return AbsolutePosition.Y;
        }
    }
}